#!/bin/bash

#注意：由kk启动的镜像仓库端口为443，请确保所有机器均可访问当前机器443端口。镜像数据存储到本地/mnt/registry (建议单独挂盘)。
docker images|grep 2d4f4b5309b1 || docker load < ../kubesphere-all-v3.0.0-offline-linux-amd64/kubesphere-images-v3.0.0/registry.tar
sudo mkdir -p /mnt/registry
sudo chmod 777 -R /mnt/registry

# 
sudo cp -f daemon.json /etc/docker/daemon.json
sudo systemctl restart docker
docker run -itd --name kubekey-registry -p 443:443 registry:2 

# 
sudo grep -rins "dockerhub.kubekey.local" /etc/hosts || (
  tee -a "192.168.99.1 dockerhub.kubekey.local" /etc/hosts 
)
sudo grep -rins "lb.kubesphere.local" /etc/hosts || (
  tee -a "192.168.99.10 lb.kubesphere.local" /etc/hosts 
)
# docker registry服务
curl -k https://dockerhub.kubekey.local/v2/
ping -c 1 dockerhub.kubekey.local

# 导入镜像
if [ -d /mnt/registry/docker/registry/v2/ ]; then
 echo "images are ready"
else
pushd  ../kubesphere-all-v3.0.0-offline-linux-amd64/kubesphere-images-v3.0.0
 ./push-images.sh  dockerhub.kubekey.local
popd

fi

# 如果联网取镜像，设置国内的镜像源 daemon.json

